from selenium.webdriver.common.by import By
from base.page_base import BasePage


class Register(BasePage):
    """注册页面"""

    # 元素定位
    __phone = By.ID, 'phone'  # 手机号
    __password = By.ID, 'password'  # 密码
    __cl_img_code = By.CLASS_NAME, 'code'  # 点击图片验证码
    __img_code = By.ID, 'verifycode'  # 输入图片验证码
    __cl_phone_code = By.ID, 'get_phone_code'  # 获取手机验证码
    __xbox__display = By.XPATH, '//span[text()="短信发送成功"]' # 弹窗提示
    __phone_code = By.ID, 'phone_code'  # 输入手机验证码
    __reg_btn = By.CLASS_NAME, 'lg-btn'  # 注册按钮
    __assert_success_text = By.XPATH, '//*[text()="注册成功！"]' # 注册成功断言文本
    __assert_fail_text_01 = By.XPATH, '//span[text()="手机已存在!"]' # 注册失败断言文本 --> 手机号已存在

    def open_url(self):
        self.driver.get('http://121.43.169.97:8081/common/member/reg')

    def input_phone(self,phone): # 输入手机号
        self.base_input(self.__phone,phone)

    def input_password(self,password): # 输入密码
        self.base_input(self.__password,password)

    def click_img_code(self): # 点击图片验证码
        self.base_click(self.__cl_img_code)

    def input_img_code(self,img_code="8888"): # 输入图片验证码
        self.base_input(self.__img_code,img_code)

    def get_phone_code(self): # 获取手机验证码
        self.base_click(self.__cl_phone_code)

    def input_phone_code(self,phone_code="666666"): # 输入手机验证码
        self.fd_element_visible(self.__xbox__display)
        self.fd_wait_element_disappear(self.__xbox__display)
        self.base_input(self.__phone_code,phone_code)

    def click_reg_btn(self): # 点击注册按钮
        self.base_click(self.__reg_btn)

    def assert_register_success(self): # 获取注册成功断言文本
        return self.base_get_text(self.__assert_success_text)

    def assert_register_fail_01(self): # 获取注册失败断言文本 --> 手机已存在
        return self.base_get_text(self.__assert_fail_text_01)

    def register(self,phone,password,img_code,phone_code):
        self.input_phone(phone)
        self.input_password(password)
        self.click_img_code()
        self.input_img_code(img_code)
        self.get_phone_code()
        self.input_phone_code(phone_code)
        self.click_reg_btn()
